<template>
  <div class="zuida">
    <div class="dl">
      <div class="text">
        <h2>登录</h2>
      </div>
      <el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
  <el-input type="name" prefix-icon="el-icon-user" v-model="ruleForm.name" placeholder="请输入用户名"></el-input>
  <el-input type="password" prefix-icon="el-icon-lock" v-model="ruleForm.password" show-password placeholder="请输入密码"></el-input>
  
  <el-form-item>
    <el-button type="primary" @click="submitForm('ruleForm')">提交</el-button>
    <el-button @click="resetForm('ruleForm')">重置</el-button>
  </el-form-item>
</el-form>
<!-- <div class="zhuce">
  没有账号?点击 <a href="/zhuce">注册</a>
</div> -->
    </div>
    
  </div>
</template>
<script>
  export default {
    data() {
      
      return {
        ruleForm: {
          password: '',
          name: ''
        },
      };
    },
    mounted(){
      this.$store.commit('noShow')
    },
    methods: {
      request(){
        this.axios.post("/login",this.ruleForm
        ).then((res)=>{
          this.$message({
          showClose: true,
          message: this.ruleForm.name+'恭喜你，登录成功!',
          type: 'success'
        })
        //登录成功,保存token
        this.token=res.data.data;
        console.log(res.data.data);
        localStorage.setItem('token',res.data.data)
        localStorage.setItem('username',this.ruleForm.name)
        
        this.$router.push("/main")
        this.$router.go(0)
      }).catch((err)=>{
        this.$message({
          showClose: true,
          message: '抱歉!登录失败!',
          type: 'warning'
        });
      })
      },
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            this.request();
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
      resetForm(formName) {
        // this.$refs[formName].resetFields();
        this.ruleForm.name=''
        this.ruleForm.password=''
      }
    }
  }
</script>
<style lang="less" scoped>
*{
  // margin: 0;
  // padding: 0;
  // list-style: none;
}
.zuida{
  width: 100%;
  height: 98vh;
  // background-color: skyblue;
  background: linear-gradient(rgba(217, 212, 212, 0.337), rgba(222, 220, 220, 0.5)), url('../img/main.jpg') no-repeat 0% 20%/ cover;

  // background-image: url("../img/main.jpg");
    /* 背景图不平铺 */
    background-repeat: no-repeat;
    /* 让背景图基于容器大小伸缩 */
    background-size: cover;
  display: flex;
  // flex-direction:column;
  justify-content:center;
  position: relative;
}
.dl{
  // background-color: rgba(0, 255, 255, 0.529);
  background:linear-gradient(rgba(179, 205, 205, 0.639),rgba(141, 229, 201, 0.821),rgba(164, 235, 223, 0.836));
  position: absolute;
    width: 370px;
    height: 218px;
    top:30vh;
    border-radius: 16px;
    box-shadow: 2px 2px 10px #7e7e7e;
  }
  .text{
    width: 100%;
    height: 40px;
    text-align: center;
  }
  .zhuce{
    text-align: center;
    margin-top: -16px;
    width: 100%;
    height: 30px;
  }
  /deep/ .el-form{
    width: 80%;
    margin-left: 10%;
  }
</style> 